<?php
/*
Plugin Name: HidePost
Plugin URI: http://nguyenthanhcong.com/2007/03/27/hidepost-plugin-for-wordpress/
Description: Protect a part of your post by using [protect] and [/protect]  between the protected content.
Version: 1.3
Author: Fu4ny
Author URI: http://nguyenthanhcong.com
*/
//Config
$blog_url = get_bloginfo('url');
$showtext = 'Please <a href="'.$blog_url.'/wp-login.php">Login</a> or <a href="'.$blog_url.'/wp-register.php">Register</a> to read the rest of this content.';
$bbproc = '[protect]';
$bbproc_c = '[/protect]';
//End of Editting

add_filter('the_content', 'code_protect_parser');
function code_protect_parser($content) {
global $current_user, $user_ID, $showtext, $bbproc, $bbproc_c;
$code_start = strpos($content, $bbproc); // Find the begin tag
$code_end = strpos($content, $bbproc_c,$code_start); // Find the end tag
if (($code_start !== false) && ($code_end !== false)) {// If has protect tag
    if (($current_user->id == 0) && ($user_ID == 0)){ // If not register or not logged in
        $newcontent = '';$rest_content = $content;
        while ((($code_start = strpos($rest_content, $bbproc)) !== false) && (($code_end = strpos($rest_content, $bbproc_c,$code_start)) !== false)){
        $code_end += strlen($bbproc_c);
        $text_start = substr($rest_content,0,$code_start); //Get the string
        $new_content .= $text_start.'<p>'.$showtext.'<br />'; //Add to content
        $rest_content = substr($rest_content,$code_end,strlen($rest_content)); //Get the rest
        }
        $new_content .= $rest_content;//Get the rest
        } else {
                $new_content = $content;
                $new_content = str_replace($bbproc,'',$new_content); //Remove tag
                $new_content = str_replace($bbproc_c,'',$new_content); //Remove tag
               }
    return $new_content;
} else { return $content; }
}
?>